<template>
  <el-upload
    v-bind="field.type_options"
    :action="`${BASE_API}/upload?storage=qiniu`"
    :limit="1"
    :file-list="
      form[field.property] ? [{name: form[field.property], url: form[field.property]}] : []
    "
    accept="file"
    :on-remove="(file, fileList) => {
      form[field.property] = ''
    }"
    :on-success="(res, file) => {
      form[field.property] = res.data[0]
    }"
    v-on="field.type_events"
  >
    <el-button size="small" type="primary">点击选择媒体文件</el-button>
    <div slot="tip" class="el-upload__tip">请上传mp4格式文件，视频文件上传会比较慢，请耐心等待上面出现文件的网址再保存</div>
  </el-upload>
</template>

<script>
import SIP from '@/utils/simple-image-process'
export default {
  props: {
    form: {
      type: Object,
      default: () => { return {} }
    },
    field: {
      type: Object,
      default: () => { return {} }
    }
  },
  data() {
    return {
      // base api
      BASE_API: process.env.VUE_APP_BASE_API
    }
  },
  methods: {
    // Get picture
    getPicture(url) { return SIP.getPicture(url) }
  }
}
</script>
